//
//  CSGXCommPreviewCell.m
//  CarSalesMS_GCX
//
//  Created by Ssky on 2016/12/1.
//  Copyright © 2016年 Tony. All rights reserved.
//

#import "CSGXCommPreviewCell1.h"

@interface CSGXCommPreviewCell1 ()

@property (nonatomic,weak) UILabel *lblName;
@property (nonatomic,weak) UILabel *lblIndex;
@property (nonatomic,weak) UILabel *lblProductDate;
@property (nonatomic,weak) UILabel *lblCount;
@property (nonatomic,weak) UILabel *lblPrice;

@end

@implementation CSGXCommPreviewCell1


#pragma mark - methods

- (void)distribute {
    
    NSString *unitCountStr = @"";
    
    NSArray *unitArr = [self.saleCommPreviewModel.sUnit componentsSeparatedByString:@","];
    NSArray *countArr = [self.saleCommPreviewModel.sCount componentsSeparatedByString:@","];
    NSArray *priceArr = [self.saleCommPreviewModel.sPrice componentsSeparatedByString:@","];
    
    for (int i = 0; i < unitArr.count; i++) {
        unitCountStr = [unitCountStr stringByAppendingFormat:@"%@%@", countArr[i], unitArr[i]];
    }

    self.lblName.text = [NSString stringWithFormat:@"       %@", self.saleCommPreviewModel.sName];
    self.lblIndex.text = [NSString stringWithFormat:@"%ld", [self.dataCommPreviewDict[@"rowIndex"] integerValue] + 1];
    self.lblProductDate.text = [CSGXDateFormatterManager getDayWithDate:[[CSGXDateFormatterManager sharedManager] dateFromString:self.saleCommPreviewModel.sCreateTime]];
    self.lblCount.text = unitCountStr;
    self.lblPrice.text = [NSString stringWithFormat:@"%@/%@", priceArr[0], unitArr[0]];
}



#pragma mark - setupUI
- (void)setupUI {

    //lblName
    UILabel *lblName = [UILabel gx_labelWithText:@"" fontSize:12 color:[UIColor blackColor]];
    [self.contentView addSubview:lblName];
    
    [lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.leading.equalTo(self.contentView).offset(5);
        make.trailing.equalTo(self.contentView).offset(-5);
    }];

    //lblIndex
    UILabel *lblIndex = [UILabel gx_labelWithText:@"0" fontSize:12 color:[UIColor whiteColor]];
    [self.contentView addSubview:lblIndex];
    [self.contentView bringSubviewToFront:lblIndex];
    
    lblIndex.backgroundColor = [UIColor orangeColor];
    lblIndex.textAlignment = NSTextAlignmentCenter;
    
    [lblIndex mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.leading.equalTo(self.contentView).offset(5);
        make.size.mas_offset(CGSizeMake(18, 15));
    }];
    
    //lblProductDate
    UILabel *lblProductDate = [UILabel gx_labelWithText:@"" fontSize:12 color:[UIColor grayColor]];
    [self.contentView addSubview:lblProductDate];
    
    [lblProductDate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblName.mas_bottom).offset(5);
        make.leading.equalTo(lblName);
    }];
    
    //lblCount
    UILabel *lblCount = [UILabel gx_labelWithText:@"" fontSize:12 color:kColorGrassGreen]; //草绿色
    [self.contentView addSubview:lblCount];
    
    [lblCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblProductDate.mas_bottom).offset(3);
        make.leading.equalTo(lblName);
    }];

    //lblPrice
    UILabel *lblPrice = [UILabel gx_labelWithText:@"" fontSize:12 color:[UIColor grayColor]];
    [self.contentView addSubview:lblPrice];
    
    [lblPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblCount.mas_bottom);
        make.leading.equalTo(lblName);
        make.bottom.equalTo(self.contentView).offset(-3);
    }];
    
    [self layoutIfNeeded];
    //
    self.lblName = lblName;
    self.lblIndex = lblIndex;
    self.lblProductDate = lblProductDate;
    self.lblCount = lblCount;
    self.lblPrice = lblPrice;
}




#pragma mark - setter & getter
- (void)setDataCommPreviewDict:(NSDictionary *)dataCommPreviewDict {
    _dataCommPreviewDict = dataCommPreviewDict;
    self.saleCommPreviewModel = dataCommPreviewDict[@"saleCommPreviewModel"];
    
    [self distribute];
}



@end
